package com.kaiyidiannao.model.req.model;

import android.util.Log;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.model.Result;
import com.kaiyidiannao.model.req.base.BaseCommand;
import org.json.JSONObject;

import java.util.HashMap;

/**
 *   删除点赞异步请求
 */
public class PostDeleteMessageInfo extends BaseCommand {

    private String fid; //当前分类编号
    private String userid =  DataCenter.userLogin.get(0).getUserid(); //用户id
    private String action = ""; //添加数据
    private String TAG = "PostDeleteMessageInfo";
    private String itemid ;
    private String title;
    private int info = -10;
    private String catid;

    public PostDeleteMessageInfo(String userid,String action,String itemid,String catid,int info) {
        this.itemid = itemid;
        this.userid = userid;
        this.action = action;
        this.info = info;
        this.catid = catid;
    }

    public PostDeleteMessageInfo(String fid, String userid,String action) {
        this.fid = fid;
        this.userid = userid;
        this.action = action;
    }

    @Override
    public String getRequestUrl() {
        return DataCenter.POST_FAVORITES_ADDRESS;
    }

    @Override
    public HashMap<String, String> getRequestParamters() {
        HashMap<String, String> paramters = new HashMap<String, String>();
        if(fid!=null&&!fid.equals("")){
            paramters.put("fid", fid  + "");
        }
        if(userid!=null&&!userid.equals("")){
            paramters.put("userid",userid + "");
        }
        if(action!=null&&!action.equals("")){
            paramters.put("action",action + "");
        }
        if(itemid!=null&&!itemid.equals("")){
            paramters.put("itemid",itemid + "");
        }
        if(title!=null&&!title.equals("")){
            paramters.put("title",title);
        }
        if(null!=catid&&!"".equals(catid)){
            paramters.put("catid",catid);
        }
        if(info!=-10){
            paramters.put("info",info+"");
        }
        return paramters;
    }

    @Override
    public Result go(String url, HashMap<String, String> paramters) { // 联网时后台执行
        // 根据请求参数返回请求数据
        return HttpUtils.postByHttpClient(url, paramters);
    }

    @Override
    public void yes(Result result) { //后台执行完毕后执行
        super.yes(result);
        Log.d(DataCenter.LOG_INFO, "GetAddMessageInfo.yes()");
        DataCenter.getInstance().callBacks(DataCenter.flag.POST_DELETE_MESSAGE_SUCCESS);
    }

    @Override
    public void no(Result result) {
        super.no(result);
        Log.d(DataCenter.LOG_ERROR, "PostDeleteMessageInfo.no()");
        DataCenter.getInstance().callBacks(DataCenter.flag.POST_DELETE_MESSAGE_FAILED);
    }
}
